package com.niiwoo.civet.trade.service.local.newRefund.dispatch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;

@Service
public class RefundValidateService
{
    @Autowired
    private Validator springValidator;

    public void validate(Object freezeRequestDTO){
        Errors errors = new BindException(freezeRequestDTO,"请求参数");
        springValidator.validate(freezeRequestDTO,errors);
        if(errors.hasErrors()){
            FieldError fieldError = errors.getFieldErrors().get(0);
            throw new IllegalArgumentException(fieldError.getField().concat(fieldError.getDefaultMessage()));
        }
    }
}
